import Vue from 'vue'
import Router from 'vue-router'
import Home from './views/Home.vue'
import sss from './views/sss.vue'
import Login from './views/Login.vue'
import addEvent from './components/event/addEvent.vue'
import index from './components/event'
import UploadEvent from './components/event/UploadEvent'
import qr from './components/event/qr'
import cd from './components/event/cd'
import task from './components/task'
import TaskDetail from './components/task/TaskDetail'
import store from "./store/index.js"
import sjqr from './components/event/ConfireHandler'

Vue.use(Router)

const router =
    // export default
    new Router({
        routes: [{
            path: '/',
            redirect: '/login',
        }, {
            path: '/login',
            name: '/login',
            component: Login
        }, {
            path: '/sss',
            name: '/sss',
            component: sss
        }, {
            path: '/home',
            name: 'home',
            component: Home,
        }, {
            path: '/addEvent',
            name: 'addEvent',
            component: addEvent
        }, {
            path: '/event',
            name: 'index',
            component: index
        }, {
            path: '/UploadEvent',
            name: 'UploadEvent',
            component: UploadEvent
        }, {
            path: '/qr',
            name: 'qr',
            component: qr
        }, {
            path: '/cd/:id/:districtId',
            name: 'cd',
            component: cd
        }, {
            path: '/task',
            name: 'task',
            component: task
        }, {
            path: '/TaskDetail',
            name: 'TaskDetail',
            component: TaskDetail
        }, {
            path: '/sjqr',
            name: 'sjqr',
            component: sjqr
        }]
    })


//挂载路由导航守卫
router.beforeEach((to, form, next) => {
    if ('/login' == to.path) {
        store.commit("set_isShowBar", false);
    } else {
        store.commit("set_isShowBar", true);
    }
    if (null == sessionStorage.getItem('set_token')) {
        if (to.path !== '/login') {
            return next('/login')
        }
    }
    next();
})

export default router